<template>
  <custom-modal-page :visible.sync="visible">
    <div
      class="add-commission-container animate__faster animate__animated animate__fadeIn"
    >
      <div class="zhgd-data-report-header" :header="title">
        <a-button type="primary" class="back-button" @click="goBack">
          返回
        </a-button>
      </div>
      <div class="add-commission-body">
        <a-form-model
          ref="form"
          :model="form"
          :rules="formRules"
          :hideRequiredMark="title == '详情'"
        >
          <a-collapse v-model="activeKey">
            <a-collapse-panel key="1" :show-arrow="false">
              <!-- 自定义头部左边 -->
              <template slot="header">
                <div @click.stop class="customize-text" header="委托信息"></div>
              </template>
              <!-- 自定义头部右边边 -->
              <template slot="extra">
                <div class="customize-extra">
                  {{ activeKey.includes("1") ? "收起" : "展开" }}
                  <div
                    class="icon"
                    :class="[activeKey.includes('1') && 'active']"
                  >
                    <bj-icon-font type="xl" color="#0068B7" :size="10">
                    </bj-icon-font>
                  </div>
                </div>
              </template>
              <div class="form-content">
                <a-row>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="检测单位：" prop="orgCode">
                      <a-select
                        placeholder="请选择检测单位"
                        v-model="form.orgCode"
                        @change="changeTestUnit"
                        :disabled="title == '详情' || title == '编辑'"
                      >
                        <a-select-option
                          :value="v.orgCode"
                          v-for="v in testUnitList"
                          :key="v.id"
                        >
                          {{ v.orgName }}
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item
                      label="委托标段："
                      prop="precativeOrgCode"
                    >
                      <a-select
                        placeholder="请选择委托标段"
                        v-model="form.precativeOrgCode"
                        :disabled="title == '详情' || title == '编辑'"
                        @change="recativeChange"
                      >
                        <a-select-option
                          :value="v.orgCode"
                          v-for="v in blockList"
                          :key="v.id"
                        >
                          {{ v.orgName }}
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="委托编号：" prop="precativeNum">
                      <a-input
                        placeholder="请输入委托编号"
                        v-model="form.precativeNum"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="报告编号：" prop="reportNum">
                      <a-input
                        placeholder="请输入报告编号"
                        v-model="form.reportNum"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="样品编号：" prop="sampleNum">
                      <a-input
                        placeholder="请输入样品编号"
                        v-model="form.sampleNum"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="样品名称：">
                      <a-input
                        placeholder="请输入样品名称"
                        v-model="form.sampleName"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="样品数量：">
                      <a-input
                        placeholder="请输入样品数量"
                        v-model="form.sampleNumber"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :xs="24" :sm="24" :md="24">
                    <a-form-model-item label="样品描述：">
                      <a-input
                        placeholder="请输入样品描述"
                        v-model="form.sampleDesc"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>

                <a-row>
                  <!-- 试验信息 -->
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="试验组数：" prop="groupCount">
                      <a-select
                        placeholder="请选择试验组数"
                        v-model="form.groupCount"
                        :disabled="title == '详情' || title == '编辑'"
                      >
                        <a-select-option
                          :value="v"
                          v-for="(v, i) in precativeMaxNum"
                          :key="i"
                        >
                          {{ v }}
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="!isLQ"
                  >
                    <a-form-model-item label="代表位置：" prop="locationType">
                      <a-radio-group
                        v-model="form.locationType"
                        :disabled="title == '详情'"
                        @change="changePosition"
                      >
                        <a-radio :value="0"> 桥梁 </a-radio>
                        <a-radio :value="1"> 其他 </a-radio>
                      </a-radio-group>
                    </a-form-model-item>
                  </a-col>

                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="!isLQ"
                  >
                    <a-form-model-item
                      label="桥梁构件"
                      prop="pierCode"
                      v-if="form.locationType == 0"
                    >
                      <a-input
                        v-if="title == '详情'"
                        v-model="bigNames"
                        disabled
                      ></a-input>
                      <a-tree-select
                        v-else
                        v-model="form.pierCode"
                        multiple
                        show-search
                        style="width: 100%"
                        :dropdown-style="{
                          maxHeight: '400px',
                          overflow: 'auto',
                        }"
                        placeholder="请选择桥梁构件"
                        allow-clear
                        :tree-data="treeSelectData"
                        :replaceFields="{
                          children: 'child',
                          title: 'name',
                          key: 'code',
                          value: 'code',
                        }"
                        @change="treeSelectChange"
                        :maxTagCount="2"
                      >
                      </a-tree-select>
                    </a-form-model-item>
                    <a-form-model-item
                      label="其他位置"
                      prop="otherLocation"
                      v-if="form.locationType == 1"
                    >
                      <a-input
                        placeholder="请输入其他位置"
                        v-model="form.otherLocation"
                        :disabled="title == '详情'"
                        :maxLength="255"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="!isLQ"
                  >
                    <a-form-model-item label="取样地点：">
                      <a-input
                        placeholder="请输入取样地点"
                        v-model="form.samplingSpot"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="isLQ"
                  >
                    <a-form-model-item
                      label="取样地点："
                      prop="LQotherLocation"
                    >
                      <a-input
                        placeholder="请输入取样地点"
                        v-model="form.LQotherLocation"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="取样日期：">
                      <a-date-picker
                        placeholder="请选择取样日期"
                        v-model="form.samplingDate"
                        format="YYYY-MM-DD"
                        valueFormat="YYYY-MM-DD"
                        :disabled="title == '详情'"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="childTrialNum != $trialNum.GCJC"
                  >
                    <a-form-model-item label="判定依据：" prop="judgeBasis">
                      <a-input :value="form.judgeBasis" disabled />
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="childTrialNum != $trialNum.GCJC"
                  >
                    <a-form-model-item
                      :label="`${trialName}` + '数据来源：'"
                      prop="dataSource"
                    >
                      <a-radio-group
                        v-model="form.dataSource"
                        :disabled="title == '详情' || title == '编辑'"
                      >
                        <a-radio :value="1"> 自动 </a-radio>
                        <a-radio :value="0"> 手动 </a-radio>
                      </a-radio-group>
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="12"
                    :xl="8"
                    :xxl="6"
                    v-if="
                      form.dataSource == 1 && childTrialNum != $trialNum.GCJC
                    "
                  >
                    <a-form-model-item label="试验仪器：" prop="equCode">
                      <a-select
                        placeholder="请选择试验仪器"
                        v-model="form.equCode"
                        :disabled="title == '详情' || title == '编辑'"
                      >
                        <a-select-option
                          :value="v.equCode"
                          v-for="v in equList"
                          :key="v.id"
                        >
                          {{ v.equName }}
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    v-if="childTrialNum != $trialNum.GCJC"
                  >
                    <a-form-model-item
                      label="物料来源："
                      prop=""
                      class="material"
                    >
                      <a-input :value="form.codes" disabled />
                      <a-button
                        type="primary"
                        @click="openChooseMaterial"
                        :disabled="!form.parentOrgCode || title == '详情'"
                        >选择物料</a-button
                      >
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </div>
            </a-collapse-panel>
            <a-collapse-panel key="2" :show-arrow="false">
              <!-- 自定义头部左边 -->
              <template slot="header">
                <div @click.stop class="customize-text" header="样品信息"></div>
              </template>
              <!-- 自定义头部右边边 -->
              <template slot="extra">
                <div class="customize-extra">
                  {{ activeKey.includes("2") ? "收起" : "展开" }}
                  <div
                    class="icon"
                    :class="[activeKey.includes('2') && 'active']"
                  >
                    <bj-icon-font type="xl" color="#0068B7" :size="10">
                    </bj-icon-font>
                  </div>
                </div>
              </template>
              <component
                :is="childTrialNum"
                ref="child"
                :title="title"
                :trialNum="childTrialNum"
              ></component>
            </a-collapse-panel>
            <a-collapse-panel key="3" :show-arrow="false">
              <!-- 自定义头部左边 -->
              <template slot="header">
                <div @click.stop class="customize-text" header="其他信息"></div>
              </template>
              <!-- 自定义头部右边边 -->
              <template slot="extra">
                <div class="customize-extra">
                  {{ activeKey.includes("3") ? "收起" : "展开" }}
                  <div
                    class="icon"
                    :class="[activeKey.includes('3') && 'active']"
                  >
                    <bj-icon-font type="xl" color="#0068B7" :size="10">
                    </bj-icon-font>
                  </div>
                </div>
              </template>
              <div class="form-content">
                <a-row>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="收样人：">
                      <a-input
                        placeholder="请输入收样人"
                        v-model="form.collectMan"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="合同段编号：">
                      <a-input
                        placeholder="请输入合同段编号"
                        v-model="form.contractNum"
                        :disabled="title == '详情'"
                        :maxLength="200"
                      />
                    </a-form-model-item>
                  </a-col>

                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="见证单位：">
                      <a-input
                        placeholder="请输入见证单位"
                        v-model="form.witnessCompany"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="见证人：">
                      <a-input
                        placeholder="请输入见证人"
                        v-model="form.witnessMan"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="要求完成日期：">
                      <a-date-picker
                        placeholder="请选择要求完成日期"
                        v-model="form.completeDate"
                        format="YYYY-MM-DD"
                        valueFormat="YYYY-MM-DD"
                        :disabled="title == '详情'"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="委托日期：">
                      <a-date-picker
                        placeholder="请选择委托日期"
                        v-model="form.precativeDate"
                        format="YYYY-MM-DD"
                        valueFormat="YYYY-MM-DD"
                        :disabled="title == '详情'"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="委托单位：">
                      <a-input
                        placeholder="请输入委托单位"
                        v-model="form.precativeCompany"
                        :disabled="title == '详情'"
                        :maxLength="100"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="委托人：">
                      <a-input
                        placeholder="请输入委托人"
                        v-model="form.precativeMan"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="委托人电话：">
                      <a-input
                        placeholder="请输入委托人电话"
                        v-model="form.precativePhone"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" :xxl="6">
                    <a-form-model-item label="机构类别：">
                      <a-input
                        placeholder="请输入机构类别"
                        v-model="form.institution"
                        :disabled="title == '详情'"
                        :maxLength="50"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </div>
            </a-collapse-panel>
          </a-collapse>
          <div class="form-footer" v-if="title != '详情'">
            <a-button @click="goBack()" class="back-button"> 取消 </a-button>
            <a-button @click="submit" :loading="loading" type="primary">
              提交
            </a-button>
          </div>
        </a-form-model>
      </div>
      <!-- 选择物料弹窗 -->
      <ChooseMaterial
        :orgCode="form.parentOrgCode"
        :typeName="typeName"
        :visible.sync="chooseMaterial.visible"
        :selectListData.sync="selectListData"
        :selectedRowKeys.sync="selectedRowKeys"
        :codes.sync="form.codes"
      ></ChooseMaterial>
    </div>
  </custom-modal-page>
</template>
<script>
import { getLoginData } from "@/tools";
import { notificationTip } from "@/utils";
import {
  getTestUnitByUserIdAndTenantCode,
  getBlockList,
  trialInfo,
  equlist,
  addCommission,
  commissionDetail,
  editCommission,
} from "@/api/wisdom-beam/trial-app";
import { getScheduleWbs } from "@/api/wisdom-beam/trial-app.js";
import ChooseMaterial from "../components/ChooseMaterial";
import SN from "../components/SN";
import SNHNT from "../components/SNHNT";
import SJ from "../components/SJ";
import LQWL from "../components/LQWL";
import LQHHL from "../components/LQHHL";
import GJYC from "../components/GJYC";
import GJHJ from "../components/GJHJ";
import GJLJ from "../components/GJLJ";
import SNJJ from "../components/SNJJ";
import WJJHL from "../components/WJJHL";
import YJCL from "../components/YJCL";
import GCJC from "../components/GCJC";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    params: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  components: {
    ChooseMaterial,
    SN,
    SNHNT,
    SJ,
    LQWL,
    LQHHL,
    GJYC,
    GJHJ,
    GJLJ,
    SNJJ,
    WJJHL,
    YJCL,
    GCJC,
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.initPage();
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      chooseMaterial: {
        visible: false,
      },
      selectedRowKeys: [],
      selectListData: [],

      childTrialNum: "",
      title: "",
      trialNum: "",
      reportId: "",
      activeKey: ["1", "2", "3"],
      trialType: "",
      form: {
        codes: "", //入库单号
        materialIds: "", //物料id
        trialNum: "", //试验类型
        parentNum: "", //父类试验类型
        // 委托信息
        orgCode: undefined, //检测单位
        parentOrgCode: "", //检测单位
        precativeOrgCode: undefined, //委托标段
        precativeNum: "", //委托编号
        reportNum: "", //报告单号
        sampleNum: "", //样品编号
        sampleName: "", //样品名称
        sampleNumber: "", //样品数量
        sampleDesc: "", //样品描述
        groupCount: undefined, //试验数组
        locationType: 0, //代表位置
        pierName: [], //桥梁构件
        pierId: [],
        pierCode: undefined,
        otherLocation: "", //其他位置
        LQotherLocation: "", //其他位置
        samplingSpot: "", //取样地点
        samplingDate: "", //取样日期
        judgeBasis: "", //判断依据
        dataSource: "", //数据来源
        equCode: undefined, //试验仪器 设备编号
        // 其他信息
        collectMan: "", //收样人
        contractNum: "", //合同段编号
        witnessCompany: "", //见证单位
        witnessMan: "", //见证人
        completeDate: "", //要求完成日期
        precativeDate: "", //委托日期
        precativeCompany: "", //委托单位
        precativeMan: "", //委托人
        precativePhone: "", //委托人电话
        institution: "", //机构类别
      },
      formRules: {
        trialNum: [
          {
            required: true,
            message: "请选择检测项目",
            trigger: "change",
          },
        ],
        orgCode: [
          {
            required: true,
            message: "请选择检测单位",
            trigger: "change",
          },
        ],
        precativeOrgCode: [
          {
            required: true,
            message: "请选择委托标段",
            trigger: "change",
          },
        ],
        precativeNum: [
          {
            required: true,
            message: "请输入委托编号",
            trigger: "blur",
          },
        ],
        reportNum: [
          {
            required: true,
            message: "请输入报告编号",
            trigger: "blur",
          },
        ],
        sampleNum: [
          {
            required: true,
            message: "请输入样品编号",
            trigger: "blur",
          },
        ],
        groupCount: [
          {
            required: true,
            message: "请选择试验组数",
            trigger: "change",
          },
        ],
        locationType: [
          {
            required: true,
            message: "请选择代表位置",
            trigger: "change",
          },
        ],
        pierCode: [
          {
            required: true,
            message: "请选择桥梁构建",
            trigger: ["change", "blur"],
          },
        ],
        otherLocation: [
          {
            required: true,
            message: "请输入其他位置",
            trigger: "blur",
          },
        ],
        LQotherLocation: [
          {
            required: true,
            message: "请输入取样地点",
            trigger: "blur",
          },
        ],
        judgeBasis: [
          {
            required: true,
            message: "请输入判断依据",
            trigger: "blur",
          },
        ],
        dataSource: [
          {
            required: true,
            message: this.message,
            validator: this.dataSourceCheck.bind(this),
          },
        ],
        equCode: [
          {
            required: true,
            message: "请选择试验仪器",
            trigger: "change",
          },
        ],
      },
      message: "请选择数据来源",
      trialName: "",
      typeName: "", //选择物料时需要

      testUnitList: [], //检测单位列表
      blockList: [], //委托标段列表
      precativeMaxNum: "", //试验组数
      equList: [], //试验仪器
      jcProjects: [], //检测项目列表

      isLQ: false,

      loading: false,
      treeSelectData: [], //桥梁构件
      bigNames: "",
    };
  },
  methods: {
    initPage() {
      this.form = {
        codes: "", //入库单号
        materialIds: "", //物料id
        trialNum: "", //试验类型
        parentNum: "", //父类试验类型
        // 委托信息
        orgCode: undefined, //检测单位
        parentOrgCode: "", //检测单位
        precativeOrgCode: undefined, //委托标段
        precativeNum: "", //委托编号
        reportNum: "", //报告单号
        sampleNum: "", //样品编号
        sampleName: "", //样品名称
        sampleNumber: "", //样品数量
        sampleDesc: "", //样品描述
        groupCount: undefined, //试验数组
        locationType: 0, //代表位置
        pierName: [], //桥梁构件
        pierId: [],
        pierCode: undefined,
        otherLocation: "", //其他位置
        LQotherLocation: "", //其他位置
        samplingSpot: "", //取样地点
        samplingDate: "", //取样日期
        judgeBasis: "", //判断依据
        dataSource: "", //数据来源
        equCode: undefined, //试验仪器 设备编号
        // 其他信息
        collectMan: "", //收样人
        contractNum: "", //合同段编号
        witnessCompany: "", //见证单位
        witnessMan: "", //见证人
        completeDate: "", //要求完成日期
        precativeDate: "", //委托日期
        precativeCompany: "", //委托单位
        precativeMan: "", //委托人
        precativePhone: "", //委托人电话
        institution: "", //机构类别
      };
      let { title, trialNum, reportId, parentNum } = this.params;
      this.title = title;
      this.trialNum = trialNum;
      this.reportId = reportId;
      this.form.trialNum = trialNum;
      this.form.parentNum = parentNum;
      this.childTrialNum = this.trialNum;
      // 沥青
      if (this.trialNum == "LQWL" || this.trialNum == "LQHHL") {
        this.form.locationType = 1;
        this.isLQ = true;
      }
      // 工程检测
      if (this.form.parentNum == this.$trialNum.GCJC) {
        this.childTrialNum = this.form.parentNum;
      }
      this.getData();
    },

    dataSourceCheck(rule, value, callbackFn) {
      if (value == "1" || value == "0") {
        callbackFn();
      }
      if (value == "") {
        this.message = "请选择" + this.trialName + "数据来源";
        callbackFn(this.message);
      }
    },
    changePosition(value) {
      if (this.form.locationType == 0) {
        this.positionTxt = "桥梁构件";
        this.$refs["form"].clearValidate(["otherLocation"]);
      }
      if (this.form.locationType == 1) {
        this.positionTxt = "其他位置";
        this.$refs["form"].clearValidate(["pierCode"]);
      }
    },
    //打开选择物料弹窗
    openChooseMaterial() {
      this.chooseMaterial.visible = true;
      this.selectedRowKeys = this.selectListData.map((v) => v.id);
      if (this.title == "编辑" && this.form.materialIds) {
        this.selectedRowKeys = this.form.materialIds.split(",");
      }
    },
    getDetail() {
      let {
        SN,
        SNHNT,
        SJ,
        LQWL,
        LQHHL,
        GJYC,
        GJHJ,
        GJLJ,
        SNJJ,
        WJJHL,
        YJCL,
        GCJC,
      } = this.$trialNum;
      commissionDetail(this.reportId)
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.selectedRowKeys = result.materialIds.split(",");
          this.form.precativeOrgCode = result.precativeOrgCode;
          this.getBridgeComponentsData();
          setTimeout(() => {
            //桥梁构件
            let ids = [];
            let names = [];
            let codes = [];
            if (result?.pierName) {
              this.bigNames = result?.pierName || "";
              names = result?.pierName.split(";") || [];
              ids = result?.pierId.split(";") || [];
              codes = result?.pierCode.split(";") || undefined;
            }

            this.form = {
              codes: result.codes,
              materialIds: result.materialIds,
              trialNum: result.trialNum,
              parentNum: result.trialNum,
              // 委托信息
              orgCode: result.orgCode,
              parentOrgCode: result.parentOrgCode,
              precativeOrgCode: result.precativeOrgCode,
              precativeNum: result.precativeNum,
              reportNum: result.reportNum,
              sampleNum: result.sampleNum,
              sampleName: result.sampleName,
              sampleNumber: result.sampleNumber,
              sampleDesc: result.sampleDesc,
              groupCount: result.groupCount,
              locationType: result.locationType,
              pierId: ids,
              pierCode: codes,
              pierName: names,
              otherLocation: result.otherLocation,
              samplingSpot: result.samplingSpot,
              samplingDate: result.samplingDate,
              judgeBasis: result.judgeBasis,
              dataSource: result.dataSource,
              equCode: result.equCode,
              // 其他信息
              collectMan: result.collectMan, //收样人
              contractNum: result.contractNum, //合同段编号
              witnessCompany: result.witnessCompany, //见证单位
              witnessMan: result.witnessMan, //见证人
              completeDate: result.completeDate, //要求完成日期
              precativeDate: result.precativeDate, //委托日期
              precativeCompany: result.precativeCompany, //委托单位
              precativeMan: result.precativeMan, //委托人
              precativePhone: result.precativePhone, //委托人电话
              institution: result.institution, //机构类别
            };
            if (this.isLQ) {
              this.form.LQotherLocation = this.form.otherLocation;
            }
          });

          // 水泥
          if (this.trialNum == SN) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              kind: result.kind, //水泥品种
              strengthGrade: result.strengthGrade, //设计强度
              curingAge: result.curingAge, //养护龄期
              trialBasis: result.trialBasis, //试验依据
              batch: result.batch, //水泥批量
              codeName: result.codeName, // 代号
              batchNum: result.batchNum, //出厂批号
              produceCompany: result.produceCompany, //生产厂家
              curing: result.curing, //养护方式
              size: result.size, //试件尺寸
            };
          }
          // 水泥混凝土
          else if (this.trialNum == SNHNT) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              strengthGrade: result.strengthGrade, //设计强度
              size: result.size, //试件尺寸
              curingAge: result.curingAge, //养护龄期
              trialBasis: result.trialBasis, //试验依据
              curing: result.curing, //养护方式
              slump: result.slump, //坍落度
            };
          }
          // 砂浆
          else if (this.trialNum == SJ) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              strengthGrade: result.strengthGrade, //设计强度
              trialBasis: result.trialBasis, //试验依据
              mixNum: result.mixNum, //配合比编号
            };
          }
          // 沥青
          else if (this.trialNum == LQWL) {
            this.$refs.child.form = {
              lqType: result.lqType, //沥青名称
              asphaltNum: result.asphaltNum, //沥青类别
              asphaltLevel: result.asphaltLevel, //沥青等级
              weatherRegion: result.weatherRegion, //气候分区
              temperature: result.temperature, //延度温度值
              samplingSpotType: result.samplingSpotType, //取样地点类型
              pileNo: result.pileNo, //施工桩号
              leftOrRight: result.leftOrRight, //左右幅
              surface: result.surface, //面层
              supplierName: result.supplierName, //供应商名称
              trialBasis: result.trialBasis, //试验依据
              asphaltOrigin: result.asphaltOrigin, //沥青产地
            };
          }
          // 沥青混合料
          else if (this.trialNum == LQHHL) {
            this.$refs.child.form = {
              lqType: result.lqType, //沥青名称
              mxeType: result.mxeType, //沥青混合料种类
              roadLevel: result.roadLevel, //公路等级
              trafficType: result.trafficType, //交通路段分类
              weatherRegion: result.weatherRegion, //沥青气候分区
              pileNo: result.pileNo, //施工桩号
              leftOrRight: result.leftOrRight, //左右幅
              trialBasis: result.trialBasis, //试验依据
              pavingLevel: result.pavingLevel, //摊铺层级
            };
          }
          // 钢筋原材
          else if (this.trialNum == GJYC) {
            this.$refs.child.form = {
              brand: result.brand, //钢筋牌号
              nominalDiameter: result.nominalDiameter, //公称直径
              trialBasis: result.trialBasis, //试验依据
              steelType: result.steelType, //钢筋品种
              produceCompany: result.produceCompany, //生产厂家
              batchNum: result.batchNum, //出厂批号
              batch: result.batch, //批量
              purpose: result.purpose, //用途
            };
          }
          // 钢筋焊接接头
          else if (this.trialNum == GJHJ) {
            this.$refs.child.form = {
              brand: result.brand, //钢筋牌号
              nominalDiameter: result.nominalDiameter, //公称直径
              trialBasis: result.trialBasis, //试验依据
              steelType: result.steelType || undefined, //钢筋品种
              weldMethod: result.weldMethod, //焊接方法
              level: result.level, //钢筋级别
              produceCompany: result.produceCompany, //生产厂家
              batch: result.batch, //批量
              steelStrand: result.steelStrand, //钢绞线结构
              weldMan: result.weldMan, //焊接人
              weldLength: result.weldLength, //焊接长度
            };
          }
          // 钢筋机械连接接头
          else if (this.trialNum == GJLJ) {
            this.$refs.child.form = {
              brand: result.brand, //钢筋牌号
              nominalDiameter: result.nominalDiameter, //公称直径
              trialBasis: result.trialBasis, //试验依据
              steelType: result.steelType || undefined, //钢筋品种
              rebarConnection: result.rebarConnection, //钢筋连接方式
              jointLevel: result.jointLevel, //钢筋设计等级
              produceCompany: result.produceCompany, //生产厂家
              batch: result.batch, //批量
            };
          }
          // 水泥净浆
          else if (this.trialNum == SNJJ) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              curingAge: result.curingAge, //养护龄期
              trialBasis: result.trialBasis, //试验依据
            };
          }
          // 无机结合料
          else if (this.trialNum == WJJHL) {
            this.$refs.child.form = {
              designStrength: result.designStrength, //设计强度
              size: result.size, //试件类型
              productionMethod: result.productionMethod, //制作方法
              readStandard: result.readStandard, //读数标准
              mixtureName: result.mixtureName, //混合料名称
              pileNo: result.pileNo, //施工桩号
              matrixExplain: result.matrixExplain, //结合料说明
              trialBasis: result.trialBasis, //试验依据
            };
          }
          // 压浆材料
          else if (this.trialNum == YJCL) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              curingAge: result.curingAge, //养护龄期
              strengthGrade: result.strengthGrade, //设计强度
              curing: result.curing, //养护方式
              trialBasis: result.trialBasis, //试验依据
              size: result.size || undefined, // 试件尺寸
            };
          }
          // 工程检测
          else if (this.trialNum == GCJC) {
            this.$refs.child.form = {
              produceDate: result.produceDate, //制件日期
              surface: result.surface, //结构层
              mxeType: result.mxeType, //混合料类型
            };
          }
        })
        .catch((_) => {});
    },
    submit() {
      this.loading = true;
      let { title } = this;
      this.$refs.form.validate(async (valid) => {
        // 物料id
        this.form.materialIds = this.selectedRowKeys.join(",") || "";
        // 工程检测
        if (this.form.parentNum == GCJC) {
          this.form.dataSource = 0;
        }
        //桥梁构件
        if (this.form.pierCode) {
          this.form.pierCode = this.form.pierCode.join(";");
          this.form.pierName = this.form.pierName.join(";");
          this.form.pierId = this.form.pierId.join(";");
        } else {
          this.form.pierCode = "";
          this.form.pierName = "";
          this.form.pierId = "";
        }
        if (this.isLQ) {
          this.form.otherLocation = this.form.LQotherLocation;
        }
        this.form.trialNum = this.trialNum;
        let childForm = this.$refs.child.form,
          result = this.$refs.child.validateHandle();
        let newForm = Object.assign(this.form, childForm);
        if (valid && result) {
          if (title == "新增") {
            addCommission(newForm)
              .then((res) => {
                this.loading = false;
                notificationTip("success", "新增成功!");
                this.goBack();
              })
              .catch((_) => {
                this.loading = false;
              });
          } else if (title == "编辑") {
            this.form.id = this.reportId;
            editCommission(this.form)
              .then((res) => {
                this.loading = false;
                notificationTip("success", "编辑成功!");
                this.goBack();
                this.$parent.getTableData();
              })
              .catch((_) => {
                this.loading = false;
              });
          }
        } else {
          this.loading = false;
        }
      });
    },
    getData() {
      if (this.reportId) {
        this.getDetail();
      } else {
        this.form = {
          codes: "", //入库单号
          materialIds: "", //物料id
          trialNum: "", //试验类型
          parentNum: "", //父类试验类型
          // 委托信息
          orgCode: undefined, //检测单位
          parentOrgCode: "", //检测单位
          precativeOrgCode: undefined, //委托标段
          precativeNum: "", //委托编号
          reportNum: "", //报告单号
          sampleNum: "", //样品编号
          sampleName: "", //样品名称
          sampleNumber: "", //样品数量
          sampleDesc: "", //样品描述
          groupCount: undefined, //试验数组
          locationType: 0, //代表位置
          pierName: [], //桥梁构件
          pierId: [],
          pierCode: undefined,
          otherLocation: "", //其他位置
          LQotherLocation: "", //其他位置
          samplingSpot: "", //取样地点
          samplingDate: "", //取样日期
          judgeBasis: "", //判断依据
          dataSource: "", //数据来源
          equCode: undefined, //试验仪器 设备编号
          // 其他信息
          collectMan: "", //收样人
          contractNum: "", //合同段编号
          witnessCompany: "", //见证单位
          witnessMan: "", //见证人
          completeDate: "", //要求完成日期
          precativeDate: "", //委托日期
          precativeCompany: "", //委托单位
          precativeMan: "", //委托人
          precativePhone: "", //委托人电话
          institution: "", //机构类别
        };
      }
      this.getTestUnitList();
      this.getBlockList();
      this.trialInfo();
    },
    //委托标段切换
    recativeChange() {
      this.getBridgeComponentsData();
    },
    //查询桥梁构件
    getBridgeComponentsData() {
      getScheduleWbs(this.form.precativeOrgCode)
        .then((res) => {
          this.treeSelectData = res?.data?.result || [];
        })
        .catch((_) => {
          this.treeSelectData = [];
        });
    },
    //桥梁构件选中
    treeSelectChange(value, label, extra) {
      try {
        this.form.pierId.push(extra.triggerNode.dataRef.id);
        this.form.pierName.push(extra.triggerNode.dataRef.name);
      } catch {
        this.form.pierId = [];
        this.form.pierName = [];
      }
    },
    // 检测单位切换
    changeTestUnit(value) {
      this.form.parentOrgCode = this.testUnitList.filter(
        (v) => v.orgCode == value
      )[0].parentOrgCode;
      this.equlist();
    },
    // 获取检测单位列表
    getTestUnitList() {
      let { userId, tenantCode } = getLoginData();
      getTestUnitByUserIdAndTenantCode({
        tenantCode,
        userId,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.testUnitList = result || [];
        })
        .catch((_) => {});
    },
    // 获取委托标段列表
    getBlockList() {
      let { userId, tenantCode } = getLoginData();
      getBlockList({
        tenantCode,
        userId,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.blockList = result || [];
        })
        .catch((_) => {});
    },

    // 试验信息
    trialInfo() {
      trialInfo({
        trialNum: this.childTrialNum,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.typeName = result.typeName || "";
          this.trialName = result.trialName || "";
          this.precativeMaxNum = result.precativeMaxNum;
          this.form.judgeBasis = result.judgeBasis;
        })
        .catch((_) => {});
    },
    // 设备信息
    equlist() {
      equlist({
        orgCode: this.form.orgCode,
        trialNum: this.trialNum,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.equList = result || [];
        })
        .catch((_) => {});
    },

    goBack() {
      this.$refs.form.resetFields();
      this.$emit("update:visible", false);
    },
  },
};
</script>
<style lang="less" scoped>
.add-commission-container {
  height: 100%;
  margin: 10px;
  .custom-scrollbar();
  .back-button {
    background: #f1f2f7;
    color: var(--primary-color);
    border: 0;
  }
  .zhgd-data-report-header {
    &::before {
      content: attr(header);
      height: 18px;
      display: flex;
      align-items: center;
      border-left: 3px solid var(--primary-color);
      padding-left: 10px;
      margin-bottom: 20px;
      font-size: 18px;
      font-weight: 400;
      color: #525a5d;
      position: relative;
      top: 10px;
    }
  }

  .add-commission-body {
    //折叠面板
    /deep/.ant-collapse {
      border-top: 2px solid #f3f4f6;

      .ant-collapse-content-box {
        padding: 0;
        .base-content {
          padding: 0 130px 20px 0;
        }
        .contract-content {
          padding-bottom: 55px;
          .ant-table-fixed {
            border: 1px solid #dcdee2;
            border-bottom: 0;
          }
        }
      }
    }

    .form-content {
      padding: 0 120px 0 20px;
    }
    .form-footer {
      background: #fff;
      .flex();
      justify-content: center;
      align-items: center;
      padding: 20px;
    }
  }
}
/deep/.ant-form-item {
  display: flex;
  //   margin-bottom: 12px;
  .ant-form-item-label {
    width: 160px;
    min-width: 160px;
    white-space: pre-wrap;
    display: flex;
    justify-content: flex-end;
    line-height: 20px;
    align-items: center;
    height: 36px;
    label {
      color: #999999;
    }
  }
  .check-item-select {
    height: 126px;
    .ant-select-selection__rendered {
      height: 126px;
      .ant-select-selection__placeholder {
        margin-top: -40px !important;
      }
    }
  }
  .ant-form-item-control-wrapper {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
/deep/.ant-calendar-picker {
  width: 100%;
  min-width: unset !important;
}
.material {
  /deep/.ant-form-item-children {
    .flex();
  }
}
</style>
